package com.avantis.common.base;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

/**
 * @ClassName BaseServiceImpl
 * @Description TODO
 * @Author kirago
 * @Date 2018/11/26 19:59
 * @Version 1.0
 **/
public class BaseServiceImpl<E extends JpaRepository,T> implements BaseService<T>{

	@Autowired
	protected E repository;

	// springboot 2.0 中接口使用方法变了，findOne -> findById
	@Override
	public T findOne(int key) {
		return (T) repository.findById(key);
	}

	@Override
	public T save(T entity) {
		return (T) repository.save(entity);
	}

	@Override
	public void delete(Object key) {
		repository.delete(key);
	}

	@Override
	public List<T> findAll() {
		return repository.findAll();
	}

	@Override
	public void deleteInBatch(Iterable<T> iterable) {
		repository.deleteInBatch(iterable);
	}

	@Override
	public List<T> findAll(Example<T> iterable) {
		return repository.findAll(iterable);
	}

	@Override
	public List<T> saveAll(Iterable<T> iterable) {
		return repository.saveAll(iterable);
	}


}